package jjn.round2;

/**
 * @author Jiang Jining
 * @since 2023-05-06 7:54
 */
public class LeetCode1419_MinimumNumberOfFrogsCroaking {
    public int minNumberOfFrogs(String croakOfFrogs) {
        int c = 0, r = 0, o = 0, a = 0, k = 0, num = 0;
        for (int i = 0; i < croakOfFrogs.length(); i++) {
            if (croakOfFrogs.charAt(i) == 'c') {
                c++;
            } else if (croakOfFrogs.charAt(i) == 'r') {
                r++;
            } else if (croakOfFrogs.charAt(i) == 'o') {
                o++;
            } else if (croakOfFrogs.charAt(i) == 'a') {
                a++;
            } else if (croakOfFrogs.charAt(i) == 'k') {
                k++;
            } else {
                return -1;
            }
            if (!(c >= r && r >= o && o >= a && a >= k)) {
                return -1;
            }
            num = Math.max(num, c - k);
        }
        if (c == r && r == k && k == o && o == a) {
            return num;
        }
        return -1;
    }
}
